﻿using Microsoft.AspNetCore.Authorization;
using Simple.Services.System.Notice;
using Simple.Services.System.Notice.Model;
using Simple.Services.System.User.Models;

namespace Simple.WebApi.Controllers.System
{
    /// <summary>
    /// 消息管理
    /// </summary>
    [Route("api/SysNotice/[action]")]
    [ApiController]
    public class NoticeController : ControllerBase
    {
        private readonly NoticeService _noticeService;

        public NoticeController(NoticeService noticeService)
        {
            _noticeService = noticeService;
        }

        /// <summary>
        /// 通知查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        public async Task<AppResult> Page([FromQuery] NoticePageInputModel model)
        {
            PageExtendResultModel<NoticeModel> data = await _noticeService.GetPageAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 通知查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> MyNotice([FromQuery] NoticePageInputModel model)
        {
            PageExtendResultModel<NoticeModel> data = await _noticeService.GetPageAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 通知读取
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> Read([FromQuery] Guid Id)
        {
            var result = await _noticeService.ReadNotice(Id);
            return AppResult.Status200OK("读取成功", result);
        }

        /// <summary>
        /// 通知删除
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<AppResult> Delete([FromBody] IdInputModel input)
        {
            await _noticeService.DeleteAsync(input.Id);
            return AppResult.Status200OK("删除成功");
        }

        /// <summary>
        /// 通知新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<AppResult> Add([FromBody] NoticeInputModel model)
        {
            var fileId = await _noticeService.AddNoticeAsync(model);
            return AppResult.Status200OK("上传成功", fileId);
        }

    }
}
